﻿using AgileDevTool.Helpers;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows;

namespace AgileDevTool
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            var fileName = "app.json";
            if (File.Exists(fileName))
            {
                var json = File.ReadAllText(fileName);
                var projects = JsonConvert.DeserializeObject<List<ProjectItem>>(json);
                if (projects!=null && projects.Count > 0)
                {
                    CacheHelper.Projects=projects;
                }
            }
            base.OnStartup(e);
        }

        protected override void OnExit(ExitEventArgs e)
        {
            var fileName = "app.json";
            var json = JsonConvert.SerializeObject(CacheHelper.Projects);
            File.WriteAllText(fileName, json, Encoding.UTF8);
            base.OnExit(e);
        }
    }
}
